<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
Class ShopCarController extends Controller{
	public function index(){
		$brandModel=new \Common\Model\Brand;
//		p($_SESSION['cart']);die;
		//将bid转换为相应的bname
		//判断是否存在$_SESSION['cart']
		if(isset($_SESSION['cart'])){
		$sum=array();
		$se=$_SESSION['cart'];
		foreach ($se['goods'] as $key => $value) {
			$sum=$se['goods'][$key]['options']['bid'];
			$bname=$brandModel->where(array('bid'=>$sum))->pluck('bname');
			$se['goods'][$key]['options']['bid']=$bname;
		}
//		p($se);
		//重组数组，组合成带有店铺名的形式
		$arr=array();
		foreach ($se['goods'] as $key => $value) {
//			if()
			$arr[$value['options']['bid']][]=$se['goods'][$key];
		}
//		p($arr);
		//算商品的总数
		$numb=0;
		foreach ($arr as $key => $value) {
				$numb+=count($arr[$key]);
		}
		View::with('numb',$numb);
//		p($se);die;
		View::with('arr',$arr);
		}
		View::make();
	}
	public function del(){
		$brandModel=new \Common\Model\Brand;
		$d1=$_POST['data1'];
		$d2=$_POST['data2'];
//		p($_SESSION['cart']);
//		p($d1);p($d2);
		$sum=array();
		$se=$_SESSION['cart'];
		foreach ($se['goods'] as $key => $value) {
			$sum=$se['goods'][$key]['options']['bid'];
			$bname=$brandModel->where(array('bid'=>$sum))->pluck('bname');
			$se['goods'][$key]['options']['bid']=$bname;
		}
//		p($se);
		//重组数组，组合成带有店铺名的形式
		$arr=array();
		foreach ($se['goods'] as $key => $value) {
//			if()
			$arr[$value['options']['bid']][]=$key;
		}
//		p($arr);
		$del=$arr[$d2][$d1];
//		p($del);
		unset($_SESSION['cart']['goods'][$del]);
	}
}


 ?>